package cn.javaxxw.springboot.controller;

import cn.javaxxw.springboot.dto.PageRequest;
import cn.javaxxw.springboot.entity.User;
import cn.javaxxw.springboot.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 功能描述: 
 * @author  TuYong
 * @date  2022/9/14 14:20
 */
@RestController
@RequestMapping("user")
@RequiredArgsConstructor
@Api(tags = "用户模块接口")
public class UserController {

    private final IUserService userService;

    @PostMapping("save")
    @ApiOperation(value = "保存用户")
    public Object saveUser(@RequestBody User user){
        return userService.save(user);
    }

    @GetMapping("queryById")
    @ApiOperation(value = "根据用户id查询")
    public Object queryById(Integer id){
        return userService.getById(id);
    }

    @GetMapping("page")
    @ApiOperation(value = "分页查询")
    public Object page(PageRequest request){
        return userService.queryPage(request);
    }

    @PostMapping("delete")
    @ApiOperation(value = "根据用户id删除")
    public Object delete(Integer id){
        return userService.removeById(id);
    }
}
